package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.pojo.Announcement;
import com.example.service.AnnouncementService;
import com.example.mapper.AnnouncementMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.List;

/**
* @author Ansenown
* @description 针对表【announcement】的数据库操作Service实现
* @createDate 2025-03-20 20:16:00
*/
@Service
public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Announcement>
    implements AnnouncementService{

    @Autowired
    private AnnouncementMapper announcementMapper;

    @Override
    public List<Announcement> getAnnouncementListByMonth(int month) {
        // 获取当前年份
        int currentYear = LocalDate.now().getYear();

        // 计算当月的第一天和最后一天
        LocalDate startOfMonth = LocalDate.of(currentYear, month, 1);
        LocalDate endOfMonth = startOfMonth.with(TemporalAdjusters.lastDayOfMonth());

        // 构建查询条件
        QueryWrapper<Announcement> queryWrapper = new QueryWrapper<>();
        queryWrapper.ge("publish_time", startOfMonth); // publishTime >= 当月第一天
        queryWrapper.le("publish_time", endOfMonth);   // publishTime <= 当月最后一天

        // 执行查询
        List<Announcement> announcementList = baseMapper.selectList(queryWrapper);


        return announcementList;
    }


}




